package com.zhuo.project.k3.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhuo.common.utils.SecurityUtils;
import com.zhuo.project.k3.domain.ZzMaterialStock;
import com.zhuo.project.k3.mapper.ZzMaterialStockMapper;
import com.zhuo.project.k3.service.IZzMaterialStockService;

/**
 * 物料库存信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-03-18
 */
@Service
public class ZzMaterialStockServiceImpl implements IZzMaterialStockService
{
    @Autowired
    private ZzMaterialStockMapper zzMaterialStockMapper;

    /**
     * 查询物料库存信息
     * 
     * @param id 物料库存信息ID
     * @return 物料库存信息
     */
    @Override
    public ZzMaterialStock selectZzMaterialStockById(Long id)
    {
        return zzMaterialStockMapper.selectZzMaterialStockById(id);
    }

    /**
     * 查询物料库存信息列表
     * 
     * @param zzMaterialStock 物料库存信息
     * @return 物料库存信息
     */
    @Override
    public List<ZzMaterialStock> selectZzMaterialStockList(ZzMaterialStock zzMaterialStock)
    {
        return zzMaterialStockMapper.selectZzMaterialStockList(zzMaterialStock);
    }

    /**
     * 新增物料库存信息
     * 
     * @param zzMaterialStock 物料库存信息
     * @return 结果
     */
    @Override
    public int insertZzMaterialStock(ZzMaterialStock zzMaterialStock)
    {
        ZzMaterialStock filter = new ZzMaterialStock();
        filter.setFmaterialid(zzMaterialStock.getFmaterialid());
        filter.setFstockid(zzMaterialStock.getFstockid());
        filter.setFlot(zzMaterialStock.getFlot());
        filter.setFstockorgid(zzMaterialStock.getFstockorgid());
        List<ZzMaterialStock> filterList = zzMaterialStockMapper.selectZzMaterialStockList(filter);
        if(null != filterList && filterList.size()>0){
            Long id = filterList.get(0).getId();
            zzMaterialStock.setId(id);
            zzMaterialStock.setUpdateTime(new Date());
            zzMaterialStock.setUpdateBy(SecurityUtils.getUsername());
            return zzMaterialStockMapper.updateZzMaterialStock(zzMaterialStock);
        }
        zzMaterialStock.setCreateBy(SecurityUtils.getUsername());
        zzMaterialStock.setCreateTime(new Date());
        return zzMaterialStockMapper.insertZzMaterialStock(zzMaterialStock);
    }

    /**
     * 修改物料库存信息
     * 
     * @param zzMaterialStock 物料库存信息
     * @return 结果
     */
    @Override
    public int updateZzMaterialStock(ZzMaterialStock zzMaterialStock)
    {
        return zzMaterialStockMapper.updateZzMaterialStock(zzMaterialStock);
    }

    /**
     * 批量删除物料库存信息
     * 
     * @param ids 需要删除的物料库存信息ID
     * @return 结果
     */
    @Override
    public int deleteZzMaterialStockByIds(Long[] ids)
    {
        return zzMaterialStockMapper.deleteZzMaterialStockByIds(ids);
    }

    /**
     * 删除物料库存信息信息
     * 
     * @param id 物料库存信息ID
     * @return 结果
     */
    @Override
    public int deleteZzMaterialStockById(Long id)
    {
        return zzMaterialStockMapper.deleteZzMaterialStockById(id);
    }
}
